<!DOCTYPE html>
<html>
<head>
    <title>Compute Attribute Full</title>
</head>
<body>
    <div id="app">
        姓: <input type="text" v-model="firstName"> 名: <input type="text" v-model="lastName">
        = {{ fullName }}
        <br><br>

        <button @click="changeName">改名</button>
    </div>


    <script src="./Vue2/vue.js"></script>

    <script>
        const app = new Vue({
            el: '#app',
            data: {
                firstName: '',
                lastName: ''
            },

            methods: {
                changeName() {
                    this.fullName = '地球人'
                }
            },

            computed: {
                fullName: {
                    get() {
                        return this.firstName + this.lastName
                    },

                    set(value) {
                        this.firstName = value.slice(0, 1)
                        this.lastName = value.slice(1)
                    }
                }
            }
        })
    </script>
</body>
</html>